﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class HospitalConfig
    {

        private static HospitalConfig _instance;
        private Hospital _currentHospital;
        private Dictionary<string, Hospital> _dicHospitals;
        //医院CODE
        #region
        /// <summary>
        /// 重庆南桐总医院
        /// </summary>
        public static string HOSPITAL_CODE_CQ_NTZYY = "CQ_NT_NTZYY";
        /// <summary>
        /// 重庆市妇幼保健院
        /// </summary>
        public static string HOSPITAL_CODE_CQ_FYBJY = "CQ_FYBJY";
        /// <summary>
        /// 重庆市铜梁区人民医院
        /// </summary>
        public static string HOSPITAL_CODE_CQ_TLRMYY = "CQ_TL_TLRMYY";
        /// <summary>
        /// 陕西省平利县中医院
        /// </summary>
        public static string HOSPITAL_CODE_SX_PL_PLZYY = "SX_PL_PLZYY";
        /// <summary>
        /// 陕西省平利县县医院
        /// </summary>
        public static string HOSPITAL_CODE_SX_PL_PLXYY = "SX_PL_PLXYY";
        /// <summary>
        /// 成都市体育学院附属体育医院
        /// </summary>
        public static string HOSPITAL_CODE_SC_CD_TYFSYY = "SC_CD_TYFSYY";
        /// <summary>
        /// 成都市温江中医院
        /// </summary>
        public static string HOSPITAL_CODE_SC_CD_WJZYY = "SC_CD_WJZYY";
        /// <summary>
        /// 广西省东兰县人民医院
        /// </summary>
        public static string HOSPITAL_CODE_GX_GL_DLXRMYY = "GX_GL_DLXRMYY";
        /// <summary>
        /// 四川德昌县人民医院
        /// </summary>
        public static string HOSPITAL_CODE_SC_SCDC = "SC_LS_DCXYY";
        /// <summary>
        /// 重庆市荣昌区人民医院
        /// </summary>
        public static string HOSPITAL_CODE_CQ_RCQRMYY = "CQ_RC_RCQRMYY";
        /// <summary>
        /// 演示使用
        /// </summary>
        public static string HOSPITAL_CODE_BOCHUANG = "BOCHUANG";
        /// 福建省云霄县中医院
        /// </summary>
        public static string HOSPITAL_CODE_FJ_YXXZYY = "FJ_YX_YXXZYY";
        #endregion

        public HospitalConfig()
        {
            _dicHospitals = new Dictionary<string, Hospital>();

            DicHospitals.Add("ANES_TEST",
            new Hospital()
            {
                HospitalName = "ANES_TEST",
                Ip = "172.16.16.235",
                Port = 38017,
                DbName = "ANES_TEST",
                HospitalCode = HOSPITAL_CODE_SC_SCDC,
                TitleNameSpace = "SC.SCDC.TableTitle",
                ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC"
            });

            DicHospitals.Add("公司",
                 new Hospital()
                 {
                     HospitalName = "公司",
                     Ip = "192.168.0.113",
                     Port = 28017,
                     DbName = "ANES_TEST",
                     TitleNameSpace = "CQ.NTZYY.TableTitle"
                 });

            DicHospitals.Add("南桐总医院",
                new Hospital()
                {
                    HospitalName = "南桐总医院",
                    HospitalCode = HOSPITAL_CODE_CQ_NTZYY,
                    Ip = "192.168.35.41",
                    Port = 28017,
                    DbName = "ANES_CQNT",
                    TitleNameSpace = "CQ.NTZYY.TableTitle",
                    ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQNT",
                    ExcelClassName = "AnesSystem.Util.CQNTExcel"
                });

            DicHospitals.Add("南桐总医院235",
               new Hospital()
               {
                   HospitalName = "南桐总医院235",
                   HospitalCode = HOSPITAL_CODE_CQ_NTZYY,
                   Ip = "172.16.16.235",
                   Port = 38017,
                   DbName = "ANES_CQNT",
                   TitleNameSpace = "CQ.NTZYY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQNT",
                   ExcelClassName = "AnesSystem.Util.CQNTExcel"
               });
            DicHospitals.Add("XXXX医院",
              new Hospital()
              {
                  HospitalName = "XXXX医院",
                  HospitalCode = HOSPITAL_CODE_BOCHUANG,
                  Ip = "172.16.16.235",
                  Port = 38017,
                  WebPort = 8080,
                  DbName = "ANES_TEST",
                  TitleNameSpace = "CQ.NTZYY.TableTitle",
                  ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQNT",
                  ExcelClassName = "AnesSystem.Util.CQNTExcel"
              });

            DicHospitals.Add("铜梁区人民医院",
               new Hospital()
               {
                   HospitalName = "铜梁区人民医院",
                   HospitalCode = HOSPITAL_CODE_CQ_TLRMYY,
                   Ip = "1.1.8.166",
                   Port = 28017,
                   DbName = "ANES_CQTL",
                   TitleNameSpace = "CQ.TLRMYY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQTL",
                   ExcelClassName = "AnesSystem.Util.CQTLExcel"
               });


            DicHospitals.Add("重庆铜梁235",
               new Hospital()
               {
                   HospitalName = "铜梁区人民医院235",
                   HospitalCode = HOSPITAL_CODE_CQ_TLRMYY,
                   Ip = "172.16.16.235",
                   Port = 38017,
                   DbName = "ANES_CQTL",
                   TitleNameSpace = "CQ.TLRMYY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQTL",
                   ExcelClassName = "AnesSystem.Util.CQTLExcel"
               });

            DicHospitals.Add("重庆妇幼235",
               new Hospital()
               {
                   HospitalName = "重庆妇幼235",
                   HospitalCode = HOSPITAL_CODE_CQ_FYBJY,
                   Ip = "172.16.16.235",
                   Port = 38017,
                   DbName = "ANES_CQFY",
                   WebPort = 8082,
                   TitleNameSpace = "CQ.CQFY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQFY",
                    ExcelClassName = "AnesSystem.Util.CQFYExcel"
               });

            DicHospitals.Add("重庆妇幼本地演示",
               new Hospital()
               {
                   HospitalName = "手麻系统演示",
                   HospitalCode = HOSPITAL_CODE_CQ_FYBJY,
                   Ip = "127.0.0.1",
                   Port = 27017,
                   DbName = "ANES_CQFY",
                   WebPort = 8082,
                   TitleNameSpace = "CQ.CQFY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQFY"
               });


            DicHospitals.Add("重庆市妇幼保健院",
               new Hospital()
               {
                   HospitalName = "重庆市妇幼保健院",
                   HospitalCode = HOSPITAL_CODE_CQ_FYBJY,
                   Ip = "192.168.2.21",
                   Port = 27017,
                   DbName = "ANES_CQFY",
                   TitleNameSpace = "CQ.CQFY.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQFY",
                   ExcelClassName = "AnesSystem.Util.CQFYExcel"
               });


            DicHospitals.Add("宁陕县医院",
                 new Hospital()
                 {
                     HospitalName = "宁陕县医院",
                     Ip = "192.168.2.15",
                     Port = 27017,
                     DbName = "ANES_CQNT",
                     TitleNameSpace = "CQ.NTZYY.TableTitle"
                 });

            DicHospitals.Add("平利县医院",
               new Hospital()
               {
                   HospitalName = "平利县医院",
                   HospitalCode = HOSPITAL_CODE_SX_PL_PLXYY,
                   Ip = "10.10.5.7",
                   Port = 27017,
                   DbName = "CDPL",
                   TitleNameSpace = "SX.PLXYY.TableTitle"
               });

            DicHospitals.Add("平利县医院235",
                new Hospital()
                {
                    HospitalName = "平利县医院235",
                    HospitalCode = HOSPITAL_CODE_SX_PL_PLXYY,
                    Ip = "172.16.16.235",
                    Port = 28017,
                    DbName = "ANES_PLXYY",
                    TitleNameSpace = "SX.PLXYY.TableTitle"
                });

            DicHospitals.Add("平利县中医院",
               new Hospital()
               {
                   HospitalName = "平利县中医院",
                   HospitalCode = HOSPITAL_CODE_SX_PL_PLZYY,
                   Ip = "10.10.15.7",
                   Port = 27017,
                   DbName = "ANSE_ORPLZYY",
                   TitleNameSpace = "SX.PLZYY.TableTitle"
               });

            DicHospitals.Add("平利县中医院235",
                new Hospital()
                {
                    HospitalName = "平利县中医院235",
                    HospitalCode = HOSPITAL_CODE_SX_PL_PLZYY,
                    Ip = "172.16.16.235",
                    Port = 28017,
                    DbName = "ANES_ORPLZYY",
                    TitleNameSpace = "SX.PLZYY.TableTitle"
                });
            DicHospitals.Add("库转换测试",
                new Hospital()
                {
                    HospitalName = "库转换测试",
                    Ip = "172.16.16.235",
                    Port = 28017,
                    DbName = "ANES_CONVERT_WG",
                    TitleNameSpace = "CQ.CQFY.TableTitle",
                    ModelNameSpace = "AnesSystem.Models.Model.Hospital.CQ.CQFY"
                });
            DicHospitals.Add("成都体院",
                new Hospital()
                {
                    HospitalName = "成都体院学院附属体育医院",
                    Ip = "192.168.100.15",
                    Port = 27017,
                    DbName = "CDTY",
                    HospitalCode = HOSPITAL_CODE_SC_CD_TYFSYY,
                    TitleNameSpace = "SC.CDTY.TableTitle",
                    ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.CDTY",
                    ExcelClassName = "AnesSystem.Util.CDTYExcel"
                });
            DicHospitals.Add("成都体院235",
                new Hospital()
                {
                    HospitalName = "成都体院学院附属体育医院235",
                    Ip = "172.16.16.235",
                    Port = 38017,
                    DbName = "ANES_CDTY",
                    HospitalCode = HOSPITAL_CODE_SC_CD_TYFSYY,
                    TitleNameSpace = "SC.CDTY.TableTitle",
                    ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.CDTY",
                    ExcelClassName = "AnesSystem.Util.CDTYExcel"
                });
            DicHospitals.Add("温江中医院235",
                new Hospital()
                {
                    HospitalName = "温江中医院235",
                    Ip = "172.16.16.235",
                    Port = 29017,
                    DbName = "ANES_CDWJ",
                    HospitalCode = HOSPITAL_CODE_SC_CD_WJZYY,
                });
            DicHospitals.Add("温江中医院",
               new Hospital()
               {
                   HospitalName = "温江中医院",
                   Ip = "192.168.1.4",
                   Port = 27017,
                   DbName = "ANES_CDWJ",
                   HospitalCode = HOSPITAL_CODE_SC_CD_WJZYY,

               });
            DicHospitals.Add("东兰县人民医院235",
                new Hospital()
                {
                    HospitalName = "东兰县人民医院235",
                    Ip = "172.16.16.235",
                    Port = 38017,
                    DbName = "ANES_GXDL",
                    HospitalCode = HOSPITAL_CODE_GX_GL_DLXRMYY,
                    TitleNameSpace = "GX.DL.TableTitle",
                });
            DicHospitals.Add("东兰县人民医院",
               new Hospital()
               {
                   HospitalName = "东兰县人民医院",
                   Ip = "192.168.168.28",
                   Port = 27017,
                   DbName = "ANES_GXDL",
                   HospitalCode = HOSPITAL_CODE_GX_GL_DLXRMYY,
                   TitleNameSpace = "GX.DL.TableTitle",
               });

            DicHospitals.Add("德昌县人民医院235",
               new Hospital()
               {
                   HospitalName = "德昌县人民医院",
                   Ip = "172.16.16.235",
                   Port = 38017,
                   DbName = "ANES_SCDC",
                   HospitalCode = HOSPITAL_CODE_SC_SCDC,
                   //TitleNameSpace = "SC.SCDC.TableTitle",
                   ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",
                   ExcelClassName = "AnesSystem.Util.SCDCExcel"
               });
            DicHospitals.Add("德昌县人民医院",
              new Hospital()
              {
                  HospitalName = "德昌县人民医院",
                  Ip = "192.168.0.18",
                  Port = 28017,
                  DbName = "ANES_SCDC",
                  HospitalCode = HOSPITAL_CODE_SC_SCDC,
                  //TitleNameSpace = "SC.SCDC.TableTitle",
                  ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",
                  ExcelClassName = "AnesSystem.Util.SCDCExcel"
              });
            DicHospitals.Add("荣昌区人民医院235",
              new Hospital()
              {
                  HospitalName = "重庆市荣昌区人民医院",
                  Ip = "172.16.16.235",
                  Port = 38017,
                  DbName = "ANES_CQRC",
                  HospitalCode = HOSPITAL_CODE_CQ_RCQRMYY,
                  //TitleNameSpace = "SC.SCDC.TableTitle",
                  //  ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",

              });
            DicHospitals.Add("荣昌区人民医院",
              new Hospital()
              {
                  HospitalName = "重庆市荣昌区人民医院",
                  Ip = "192.168.169.2",
                  Port = 28017,
                  DbName = "ANES_CQRC",
                  HospitalCode = HOSPITAL_CODE_CQ_RCQRMYY,
                  //TitleNameSpace = "SC.SCDC.TableTitle",
                  //  ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",

              });
            DicHospitals.Add("福建云霄",
              new Hospital()
              {
                  HospitalName = "福建省云霄县中医院235",
                  Ip = "192.168.0.2",
                  Port = 38017,
                  DbName = "ANES_FJYX",
                  HospitalCode = HOSPITAL_CODE_FJ_YXXZYY,
                  TitleNameSpace = "FJ.YXZYY.TableTitle",
                  //  ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",

              });
            DicHospitals.Add("福建云霄235",
              new Hospital()
              {
                  HospitalName = "福建省云霄县中医院",
                  Ip = "172.16.16.235",
                  Port = 38017,
                  DbName = "ANES_FJYX",
                  HospitalCode = HOSPITAL_CODE_FJ_YXXZYY,
                  TitleNameSpace = "FJ.YXZYY.TableTitle",
                  //  ModelNameSpace = "AnesSystem.Models.Model.Hospital.SC.SCDC",

              });

        }


        public static HospitalConfig Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new HospitalConfig();
                }
                return _instance;
            }
        }

        public Dictionary<string, Hospital> DicHospitals
        {
            get
            {
                return _dicHospitals;
            }

            set
            {
                _dicHospitals = value;
            }
        }

        public Hospital CurrentHospital
        {
            get
            {
                try
                {
                    if (_currentHospital == null)
                    {
                        _currentHospital = DicHospitals[ClientAndServerHelper.Instance.LocalXMLContent.Hospital];

                        _currentHospital.Ip = ClientAndServerHelper.Instance.LocalXMLContent.SerIp;
                    }
                    return _currentHospital;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(this.GetType(), ex);
                    return DicHospitals.FirstOrDefault().Value;
                }
            }
        }

    }

    public class Hospital
    {
        private string hospitalName;
        private string hospitalCode;
        private string displayHospitalName;
        private string serverIp;
        private int serverPort;
        private int webPort = 8080;
        private string webUrl;
        private string dbName;
        private string webWorkStationUrl;
        private string webScheduleUrl;
        private string dbUser;
        private string dbPwd;
        private string titleNameSpace;
        private string modelNameSpace;
        private string excelClassName;
        private string hisIp;
        private int hisPort;
        private string lisIp;
        private string lisPort;



        public string HospitalName
        {
            get
            {
                return hospitalName;
            }

            set
            {
                hospitalName = value;
            }
        }

        public string Ip
        {
            get
            {
                return serverIp;
            }

            set
            {
                serverIp = value;
            }
        }

        public string DbName
        {
            get
            {
                return dbName;
            }

            set
            {
                dbName = value;
            }
        }

        public string TitleNameSpace
        {
            get
            {
                return "AnesSystem.Controls.CommonTableHeader.TableTitile." + titleNameSpace;
            }

            set
            {
                titleNameSpace = value;
            }
        }

        public int Port
        {
            get
            {
                return serverPort;
            }

            set
            {
                serverPort = value;
            }
        }

        public string HisIp
        {
            get
            {
                return hisIp;
            }

            set
            {
                hisIp = value;
            }
        }

        public int HisPort
        {
            get
            {
                return hisPort;
            }

            set
            {
                hisPort = value;
            }
        }

        public string LisIp
        {
            get
            {
                return lisIp;
            }

            set
            {
                lisIp = value;
            }
        }

        public string LisPort
        {
            get
            {
                return lisPort;
            }

            set
            {
                lisPort = value;
            }
        }

        public string ModelNameSpace
        {
            get
            {
                return modelNameSpace;
            }

            set
            {
                modelNameSpace = value;
            }
        }

        public string DisplayHospitalName
        {
            get
            {
                if (string.IsNullOrEmpty(displayHospitalName))
                {
                    displayHospitalName = hospitalName;
                }
                return displayHospitalName;
            }

            set
            {
                displayHospitalName = value;
            }
        }

        public string WebUrl
        {
            get
            {
                if (string.IsNullOrEmpty(webUrl))
                {
                    webUrl = string.Format("http://{0}:{1}/Anes_WebService/ZhikongController/zhikong.do", serverIp, webPort);

                }
                return webUrl;
            }

            set
            {
                webUrl = value;
            }
        }

        public int WebPort
        {
            get
            {
                return webPort;
            }

            set
            {
                webPort = value;
            }
        }

        public string WebWorkStationUrl
        {
            get
            {
                if (string.IsNullOrEmpty(webUrl))
                {
                    webWorkStationUrl = string.Format("http://{0}:{1}/Anes_WebService/ZhurengongzuozhanController/Zhurengongzuozhan.do#",
                             serverIp, webPort);
                }
                return webWorkStationUrl;
            }

            set
            {
                webWorkStationUrl = value;
            }
        }

        public string WebScheduleUrl
        {
            get
            {
                if (string.IsNullOrEmpty(webUrl))
                {
                    webScheduleUrl = string.Format("http://{0}:{1}/Anes_WebService/commandController/paibanA.do",
                             serverIp, webPort);
                }
                return webScheduleUrl;
            }

            set
            {
                webScheduleUrl = value;
            }
        }

        public string DbUser
        {
            get
            {
                return dbUser;
            }

            set
            {
                dbUser = value;
            }
        }

        public string DbPwd
        {
            get
            {
                return dbPwd;
            }

            set
            {
                dbPwd = value;
            }
        }

        public string ExcelClassName
        {
            get
            {
                if (string.IsNullOrEmpty(excelClassName))
                {
                    excelClassName = "AnesSystem.Util.ExcelBasic";
                }
                return excelClassName;
            }

            set
            {
                excelClassName = value;
            }
        }

        public string HospitalCode
        {
            get
            {
                if (hospitalCode == null)
                {
                    hospitalCode = "";
                }
                return hospitalCode;
            }

            set
            {
                hospitalCode = value;
            }
        }
    }

    public enum HospitalEnum
    {
        库转换测试,

        ANES_BASIC,
        公司,

        南桐总医院235,
        南桐总医院,

        平利县医院235,
        平利县医院,

        平利县中医院,
        平利县中医院235,

        铜梁区人民医院,
        铜梁区人民医院235,
        铜梁医院235_29017,

        重庆妇幼,
        重庆市妇幼保健院,
        重庆妇幼235,

        宁陕县医院,

        成都体院,
        成都体院235,

        温江中医院235,
        温江中医院,
        东兰县人民医院235,
        东兰县人民医院,

        德昌县人民医院235,
        德昌县人民医院,
        荣昌区人民医院,
        荣昌区人民医院235
    }
}
